package com.xzp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController  // = @ResponseBody + @Controller 可返回json
// Controller在spring中单独返回的话，得配合模板使用，参考HelloController2中的实例
public class HelloController {

//    @Value("${cupSize}")    // "${}"引用变量
//    private String cupSize;   //将配置文件的内容赋值到成员变量
//
//    @Value("${content}")
//    private String content;
    @Autowired
    GirlProperties girlProperties;

    @RequestMapping(value = {"/hello","hi"},method = RequestMethod.GET) //一种路径映射的方式
    public String say(){
//            return "Hello SpringBoot !" + cupSize + content;

        return girlProperties.getCupSize() + " " + girlProperties.getAge();
    }

    @GetMapping("/say2")
        private String say2(@PathParam("id") Integer id){ //接受路径参数
        return String.valueOf(id);
    }

    @GetMapping("/say3")
    private String say3(@RequestParam("id") Integer myId){ //接受请求参数
        return String.valueOf(myId);
    }

    @GetMapping("/say4")
    private String say4(@RequestParam(value = "id",required = false,defaultValue = "0") Integer myId){ //设置默认参数
        return String.valueOf(myId);
    }



}
